/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.swta;

/**
 *
 * @author JKorreck
 */
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;

public abstract class AddItemsToPackageModalWindow extends ModalWindow {

    public AddItemsToPackageModalWindow(String id, Component parent, MyItemPackage itemPackage) {
        super(id);

        // Set sizes of this ModalWindow. You can also do this from the HomePage
        // but its not a bad idea to set some good default values.
        setInitialWidth(500);
        setInitialHeight(500);

        setTitle("Select something");

        
        // Set the content panel, implementing the abstract methods
        setContent(new AddItemsToPackageContentPanel(this.getContentId(), parent, itemPackage) {


            @Override
            void onCancel(AjaxRequestTarget target) {
                target.appendJavascript("Wicket.Window.unloadConfirmation = false;");
                AddItemsToPackageModalWindow.this.onCancel(target);
            }

            void onSelect(AjaxRequestTarget target, String selection) {
                target.appendJavascript("Wicket.Window.unloadConfirmation = false;");
                AddItemsToPackageModalWindow.this.onSelect(target, selection);
            }
        });
    }

    public void setTitleText(String message) {
        this.setTitle(message);
    }

    public MyItemPackage getEditedItemPackage() {
        return ((AddItemsToPackageContentPanel) this.get(this.getContentId())).getEditedPackage();
    }

    public void setTextMessage(String text) {

        AddItemsToPackageContentPanel panel = ((AddItemsToPackageContentPanel) this.get(this.getContentId()));
        panel.setMessageText(text);
    }
    public void setPackageID(String packageID) {
        System.out.println("_________=????? PACKAGEID:" + packageID);
        ((AddItemsToPackageContentPanel) this.get(this.getContentId())).setPackage(MyItemPackageManager.getInstance().getItemPackage(packageID));
    }

    public void setPackage(MyItemPackage itemPackage) {
        ((AddItemsToPackageContentPanel) this.get(this.getContentId())).setPackage(itemPackage);
    }

    abstract void onCancel(AjaxRequestTarget target);

    abstract void onSelect(AjaxRequestTarget target, String selection);

}
